<template>
  <div>
    <PartInfo ref="partInfo" type="fahuodan" :partInfoRow="partInfoRow" @getEditPartInfo="getEditPartInfo" @getAddPartInfo="getAddPartInfo" @getNewPartInfo="getNewPartInfo" />
    <el-row class="btn-wrap">
      <el-button type="primary" @click="confirmBtnClick">确 定</el-button>
      <el-button @click="$emit('cancel')">取 消</el-button>
    </el-row>
    <!-- 配件库存新增 -->
    <BaseDialog title="配件库存新增" :visible.sync="addPartInfoisShow" destroyOnClose>
      <addPartInfo :formData="formData" @cancel="cancel" @addChange="addChange" />
    </BaseDialog>
    <!-- new配件库存新增 -->
    <BaseDialog title="配件库存新增" :visible.sync="newPartInfoisShow" destroyOnClose>
      <newPartInfo :formData="formData" @cancel="newCancel" @addChange="newChange" />
    </BaseDialog>
  </div>
</template>

<script>
import PartInfo from './PartInfo';
import addPartInfo from './addPartInfo';
import newPartInfo from './newPartInfo';
export default {
  name: 'cgrk_edit',
  components: {
    PartInfo,
    addPartInfo,
    newPartInfo
  },
  props: {
    selectRow: Object
  },
  data() {
    return {
      newPartInfoisShow: false,
      formData: {},
      addPartInfoisShow: false,
      partInfoRow: {}
    };
  },
  mounted() {
    window.cgrk_edit = this;
    console.log('cgrk_edit mounted', this.selectRow);
    this.partInfoRow = Object.assign({}, this.selectRow);
  },
  methods: {
    // new 新增仓库保存之后回调的值
    newChange(partInfo) {
      this.newPartInfoisShow = false;
      this.$emit('confirm', partInfo);
    },
    newCancel() {
      // 关闭弹窗
      this.newPartInfoisShow = false;
    },
    // 传值打开弹窗
    getNewPartInfo(row) {
      this.formData = row;
      this.newPartInfoisShow = true;
    },
    // 传值打开弹窗
    getAddPartInfo(row) {
      this.formData = row;
      this.addPartInfoisShow = true;
    },
    // 新增仓库保存之后回调的值
    addChange(partInfo) {
      this.addPartInfoisShow = false;
      this.$emit('confirm', partInfo);
    },
    // 关闭弹窗
    cancel() {
      this.addPartInfoisShow = false;
    },
    confirmBtnClick() {
      this.$refs.partInfo.$refs.form.SUBMIT_FORM();
    },
    getEditPartInfo(partInfo) {
      console.log('表单数据', JSON.stringify(partInfo, null, 2));
      // 给父表加的数据
      this.$emit('confirm', partInfo);
    }
  }
};
</script>

<style scoped>
.btn-wrap {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 60px;
}
</style>
